package com.xiyu.service.repository.office.area;

import com.xiyu.service.model.office.area.OfficeAreaClassFetcher;
import com.xiyu.service.model.office.area.OfficeAreaFetcher;
import com.xiyu.service.vo.area.officeArea.OfficeAreaPageQueryInput;
import com.xiyu.service.model.office.area.OfficeArea;
import com.xiyu.service.model.office.area.OfficeAreaTable;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.babyfish.jimmer.Page;

public interface OfficeAreaRepository extends JRepository<OfficeArea, Long> {
    OfficeAreaTable officeAreaTable = OfficeAreaTable.$;

    default Page<OfficeArea> pageQuery(OfficeAreaPageQueryInput inputVO){
        return
            sql().createQuery(officeAreaTable)
                    .where(officeAreaTable.name().likeIf(inputVO.getName()))
                    .where(officeAreaTable.detailAddress().likeIf(inputVO.getDetailAddress()))
                    .where(officeAreaTable.ownershipRegister().likeIf(inputVO.getOwnershipRegister()))
                    .orderBy(officeAreaTable.id().desc())
                    .select(officeAreaTable.fetch(OfficeAreaFetcher.$.allTableFields().areaClass(OfficeAreaClassFetcher.$.allTableFields())))
                    .fetchPage(inputVO.getPageNo() - 1, inputVO.getPageSize());

    }


}